#!/bin/bash

#
# credentials and svc endpoint url; change as needed.
CREDS=$(cat .auth)
TRACKS=https://tracks.bitmech.com

#
# content-type - shouldn't need to change this.
CT="Content-Type: text/xml"

#
# get list of projects
METHOD="projects.xml"
OUTPUT=$(basename ${METHOD})
curl -k -u ${CREDS} -H "${CT}" ${TRACKS}/${METHOD} > ${OUTPUT} 2>/dev/null 

#
# find just active projects
actives=$(cat projects.xml | ./print-projects.pl | awk -F\| '{print $1}')

#
# for each project, get todos
IFS="
"
for project in ${actives}
do
    METHOD="/projects/${project}/todos.xml"
    OUTPUT=$(basename ${METHOD})
    curl -k -u ${CREDS} -H "${CT}" ${TRACKS}/${METHOD} > ${OUTPUT} 2>/dev/null
    cat ${OUTPUT} | ./print-todos.pl | sed "s/^/| ${project} /g"
done 

